import { defineStore } from 'pinia'
import { ref } from 'vue'

/* 
存储用户的role和token
        "role": 2,
        "token": "xxxxx"
*/
export const useUserStore = defineStore(
  'user',
  () => {
    const role = ref(undefined)
    const token = ref(undefined)
    const userInfo = ref<any>({})
    const setRole = (val: number) => {
      role.value = val
    }
    const setUserInfo = (val: any) => {
      userInfo.value = val
    }
    const setToken = (val: string) => {
      token.value = val
    }
    const reset = () => {
      role.value = undefined
      token.value = ''
      userInfo.value = {}
    }

    return {
      role,
      token,
      userInfo,
      setRole,
      setUserInfo,
      setToken,
      reset,
    }
  },
  {
    persist: true,
  },
)
